package com.base.andlangcore.http

import android.content.Context
import android.os.Build
import com.base.andlangcore.util.BaseLangUtils
import com.google.gson.Gson
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import java.util.*
import kotlin.collections.HashMap

/**
 * 接口请求添加通用请求参数
 */
fun Map<Any, Any>.toVersionParams(content: Context): RequestBody {
    val params = this.toMutableMap()
    params["v"] = BaseLangUtils.getVersionName(content)
    params["st"] = "1"
    params["versionAndr"] = BaseLangUtils.getVersionCode(content)
    params["brand"] = Build.BRAND.lowercase(Locale.getDefault())
    return Gson().toJson(params)
        .toRequestBody("Content-Type, application/json".toMediaTypeOrNull())
}

fun toEmptyVersionParams(content:Context): RequestBody {
    val params = HashMap<Any, Any>()
    params["v"] = BaseLangUtils.getVersionName(content)
    params["st"] = "1"
    params["versionAndr"] = BaseLangUtils.getVersionCode(content)
    params["brand"] = Build.BRAND.lowercase(Locale.getDefault())
    return Gson().toJson(params)
        .toRequestBody("Content-Type, application/json".toMediaTypeOrNull())
}